﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace Hp.Vertica.Migration.SqlServer
{
    public class Database
    {
        public String Name { get; private set; }
        public ServerInstance DataSource { get; private set; }

        internal Database(String name, ServerInstance ds)
        {
            if (name == null || ds == null)
            {
                throw new ArgumentNullException();
            }
            this.Name = name;
            this.DataSource = ds;

            this.SchemaCollection = new SchemaCollection(this);
            this.UserTableCollection = new UserTableCollection(this);
            this.SystemTableCollection = new SystemTableCollection(this);
            this.UserViewCollection = new UserViewCollection(this);
            this.SystemViewCollection = new SystemViewCollection(this);
        }

        public SchemaCollection SchemaCollection { get; private set; }

        public UserTableCollection UserTableCollection { get; private set; }

        public SystemTableCollection SystemTableCollection { get; private set; }

        public UserViewCollection UserViewCollection { get; private set; }

        public SystemViewCollection SystemViewCollection { get; private set; }

        public override string ToString()
        {
            return this.Name + " - " + this.DataSource.ToString();
        }

        public override int GetHashCode()
        {
            return this.Name.ToUpper().GetHashCode() * 17 + this.DataSource.GetHashCode();
        }

        public Boolean IsSystemObject
        {
            get
            {
                String name = this.Name.ToLower();
                String[] sysdbs = new String[] { "master", "tempdb", "model", "msdb" };
                if (sysdbs.Contains(name))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}
